import React from 'react';
import {Layout} from 'antd';
import './index.less';
import {connect} from "dva";
import Curd from "components/Curd";
import {getAllDeviceType} from "../../../../models/deviceType";
import BaseComponent from "components/Base/BaseComponent";
import Button from "antd/lib/button";
import DataTable from "components/Base/DataTable";
import Icon from "components/Base/Icon";

const {Content, Footer, Header} = Layout;

@connect(({pushDetails}) => ({pushDetails}))
export default class extends BaseComponent {

  componentDidMount() {
    this.init(this.props.patientId);
  }

  componentDidUpdate(prevProps, prevState, snapshot) {
    prevProps.patientId != this.props.patientId && this.init(this.props.patientId);
  }

  getNamespace() {
    return 'pushDetails';
  }

  getTableColumns() {
    return [
      {
        title: '推送时间',
        name: 'pushTime',
        tableItem: {},
      },
      {
        title: '推送地址',
        name: 'url',
        tableItem: {},
      },
      {
        title: '响应消息',
        name: 'responseMsg',
        tableItem: {},
      },
      {
        title: '响应码',
        name: 'responseCode',
        tableItem: {},
      },
      {
        title: '状态',
        name: 'pushStatus',
        dict: [
          {code: 0, codeName: '失败'},
          {code: 1, codeName: '成功'}],
        tableItem: {},
      },
    ];
  }

  init = () => {
    this.dispatch({
      type: `${this.getNamespace()}/init`,
      payload: {
        page: {pageNum: 1, pageSize: 10, id: this.props.patientId,},
        notice: this.showMsg
      },
    })
  }
  getPageInfo = ({pageNum, pageSize, filters, sorter}) => {
    let f = {};
    if (!!filters) {
      Object.keys(filters).forEach(key => {
        !!filters[key] && (f[key] = filters[key])
      });
    }
    this.dispatch({
      type: `${this.getNamespace()}/init`,
      payload: {
        page: {pageNum: (!!pageNum ? pageNum : 1), pageSize: (!!pageSize ? pageSize : 10), id: this.props.patientId,},
        filters: f, sorter, notice: this.showMsg,
      },
    })
  }
  render() {

    console.log("render");

    const curdProps = {
      ...this.props,
      namespace: this.getNamespace(),
      tableColumns: this.getTableColumns,
      getPageInfo: this.getPageInfo,
      align: 'center',
      selectType: 'none',
      showAddDelete: false,
    }

    return (
      <div className="bind">
        <Curd {...curdProps}/>
        <div className="top">
          <Button onClick={this.init}>刷新</Button>
        </div>
      </div>
    );
  }

}
